<?php require_once ADMINVIEWPATH.'admin_header.php'; ?>
<?php require_once ADMINVIEWPATH.'admin_menu.php'; ?>
<!-- Page Content -->
            <div class="page-content">
                <!-- Page Breadcrumb -->
                <div class="page-breadcrumbs">
                    <ul class="breadcrumb">
                        <li>
                            <i class="fa fa-home"></i>
                            <a href="/luckydog/index">首页</a>
                        </li>
                        <li class="">
                            <a href="#">积分兑换</a>
                        </li>
                        <li class="">
                            兑换商品订单列表
                        </li>
                    </ul>
                </div>
                <!-- /Page Breadcrumb -->
                <!-- Page Body -->
                <div class="page-body">
                    <div class="row">
                        <div class="col-xs-12 col-md-12">
                            <div class="tab-content tabs-flat no-padding">
                                <div id="visits" class="tab-pane active animated fadeInUp">
                                    <div class="row">
                                        <div class="col-lg-12 chart-container">
                                            <div id="dashboard-chart-visits" class="chart chart-lg no-margin">
                                                <div class="widget-body">
                                                        <div>
                                                            <!-- <input class="form-control" style="width:100px;float: left;" type="text" placeholder="起始时间" id="starttime" onClick="WdatePicker({maxDate:'#F{$dp.$D(\'endtime\')||\'2120-10-01\'}'})" value="">
                                                            <input class="form-control" style="width:100px;float: left;" type="text" placeholder="结束时间" id="endtime" onClick="WdatePicker({minDate:'#F{$dp.$D(\'starttime\')}',maxDate:'2120-10-01'})" value=""> -->
                                                            <input style="float: left; padding-left:50px;width: 200px;" class="form-control "  type="text" id="keyword" placeholder="请输入搜索关键字">
                                                        </div>
                                                        <div class="control-group"  style="float: left; padding-left:10px;">
                                                            <div class="controls" >
                                                            发货状态：
                                                                <select id="choosestatus" style="width: 200px;">
                                                                        <option value = "">--请选择发货状态--</option>
                                                                        <option value = "0">不限</option>
                                                                        <option value = "1">已下单</option>
                                                                        <option value = "2">已发货</option>
                                                                        <option value = "3">已收货</option>
                                                                </select>
                                                            </div>
                                                        </div>
                                                        <div style="float: left;margin-bottom: 10px;">
                                                            <a class="btn J_search" href="javascript:;">搜索</a>
                                                        </div>
                                                        
                                                        <table class="table table-striped table-bordered table-hover" id="simpledatatable">
                                                            <thead>
                                                                <tr>
                                                                    <th style="width: 60px;">订单号</th>
                                                                    <th>商品id</th>
                                                                    <th>商品名称</th>
                                                                    <th>需要兑换的金币</th>
                                                                    <th>收货人</th>
																	<th>收货地址</th>
                                                                    <th>兑换时间</th>
                                                                    <th>状态</th>
                                                                    <th>操作</th>
                                                                </tr>
                                                            </thead>
                                                            <tbody>
                                                            <?php if(!empty($orderList)):?>
                                                            <?php foreach($orderList as $key=> $row):?>
                                                                <tr class="gradeX">
                                                                    <td class="center" style="text-align:center;width:40px;"><?php echo $row['ordernum'];?></td>
                                                                    <td class="center goodsDetail" style="cursor:pointer " data-id = "<?php echo $row['id'];?>" ><?php echo $row['goodsID'];?></td>
                                                                    <td class="center" ><?php echo $row['goodsName'];?></td>
                                                                    <td class="center" ><?php echo $row['exchangepoints'];?></td>
                                                                    <td class="center" ><?php echo $row['receiver'];?></td>
																	<td class="center" ><?php echo $row['area'];?></td>
                                                                    <td class="center"><?php echo  date("Y-m-d H:i:s",$row['createtime'])?></td>
                                                                    <td class="center">
                                                                        <?php if($row['status'] == 1){?>
                                                                            <span style="color:#E47833;">已下单</span>
                                                                        <?php }elseif($row['status'] == 2){?>
                                                                            <span style="color:green;">已发货</span>
                                                                        <?php }elseif($row['status'] == 3){?>
                                                                            已收货
                                                                        <?php }?>
                                                                    </td>
                                                                    <td class="center "  data_id = "<?php echo $row['id'];?>">
                                                                        <?php if(check_authorize("Goods","Order","status")):?>
                                                                        <?php if($row['status'] == 1){?>

                                                                            <a class="edit_status" style="color:blue;" href="javascript:;"  type="status" status="<?php echo $row['status'];?>" >确认发货</a>
                                                                        <?php }elseif($row['status'] == 2){?>
                                                                            <a class="edit_status" style="color:blue;" href="javascript:;"  type="status" status="<?php echo $row['status'];?>" >确认已收货</a>
                                                                        <?php }elseif($row['status'] == 3){?>
                                                                            已收货
                                                                        <?php }?>
                                                                        |
                                                                        <?php endif;?>
                                                                        <?php if(check_authorize("Goods","Order","detail")):?>
                                                                        <a style="color:blue;" href="javascript:;" class="J_detail">详情</a>|
                                                                        <?php endif;?>
                                                                        <?php if(check_authorize("Goods","Order","delete")):?>
                                                                        <a style="color:blue;" href="javascript:;" class="J_del">删除</a>
                                                                        <?php endif;?>
                                                                    </td>
                                                                </tr>
                                                        <?php endforeach;?>
                                                        <?php endif;?>
                                                                <tr>
                                                                    <td align='center' colspan="10">
                                                                        <div class="page_links"><?php echo $page_links?></div>
                                                                    </td>
                                                                </tr>
                                                            </tbody>
                                                        </table>
                                                    </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- /Page Body -->
        </div>
        <!-- /Page Content -->
<script src="<?php echo STATICURL; ?>js/jquery-2.0.3.min.js"></script>
<script src="<?php echo STATICURL; ?>layer/layer.js"></script>
<script src="<?php echo STATICURL; ?>js/wdatepicker/WdatePicker.js"></script>
<?php require_once ADMINVIEWPATH.'admin_footer.php'; ?>
<script>
$(".J_search").click(function(){
    var endtime = $("#endtime").val();
    var starttime = $("#starttime").val();
    var keyword = $("#keyword").val();
    var choosestatus = $("#choosestatus").val();
    var params={
        'starttime':starttime,
        'endtime':endtime,
        'keyword':keyword,
        'choosestatus':choosestatus
    };
    location = "/luckydog/goods/orderList?"+$.param(params);
});
    $(document).ready(function(){

        $('.J_detail').on('click', function(){
            //iframe窗
            var id = $(this).parent().attr("data_id");
            layer.open({
                type: 2,
                title: '订单详情',
                shade: [0.5, '#000'],
                shadeClose: false,
                maxmin: true, //开启最大化最小化按钮
                area: ['650px', '240px'],
                content: '/luckydog/goods/orderdetail?id='+id
            });
        });
        $(".J_del").click(function() {
            var id = $(this).parent().attr("data_id");
            if (confirm("您确定要删除该订单吗？")) {
                $.post("/luckydog/goods/do_orderdel", {"id":id}, function(res) {
                    if (res) {
                        window.location.reload();
                    }else{
                        layer.msg("删除失败");
                    }
                });
            }
        });  


        $(".edit_status").click(function(){
            var id = $(this).parent().attr("data_id");
            var status = $(this).attr("status");
            var alert_msg = "您确定要发货吗？";
            if(status == 1){
                status = 2;
                layer.open({
                    type: 2,
                    title: '确认发货',
                    shade: [0.5, '#000'],
                    shadeClose: false,
                    maxmin: true, //开启最大化最小化按钮
                    area: ['650px', '240px'],
                    content: '/luckydog/goods/edit_express?id='+id
                });
                return false;



            }else if(status == 2){
                alert_msg = "确认已收货吗？";
                status = 3;
            }
            if (confirm(alert_msg)) {
                $.post("/luckydog/goods/edit_order_status",{id:id,status:status},function(res){
                    if(res){
                        window.location.reload();
                    }else{
                        layer.msg("失败");
                    }
                });
            }
        });  
    });
</script>



